<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div class="datagrid-header" id="coachStaff-grid-toolbar"
		style="width: 100%;">
		<table class="datagrid-htable" border="0" cellspacing="0"
			cellpadding="0" style="width: 100%;">
			 <tr class="datagrid-header-row" style="height: 30px;">
            <td align="left" style="border-style: solid; padding-left: 48px;">
                教练名：
                <input style="width: 270px;" id="coachName"  data-options="url:'CoachStaffServlet?method=query',textField:'coachName',valueField:'cIC'">
            </td>
             
            <td align="left" style="border-style: solid;">
                教练身份证号：
                <input type="text" id="cIC" name="cIC" style="width: 266px">
            </td>
<!--             <td align="left" style="border-style: solid;"> -->
<!--                 有效状态： -->
<!--                 <input id="state" name="state" class="easyui-combobox" data-options=" -->
<!-- 				valueField: 'label', -->
<!-- 				textField: 'value', -->
<!-- 				data: [{ -->
<!-- 					label: '', -->
<!-- 					value: '请选择' -->
<!-- 				},{ -->
<!-- 					label: '0', -->
<!-- 					value: '无效' -->
<!-- 				},{ -->
<!-- 					label: '1', -->
<!-- 					value: '有效' -->
<!-- 				}]" /> -->
<!--             </td> -->
        </tr>
			
			<tr class="datagrid-header-row" style="height: 40px;">
				<td colspan="6" align="left" style="border-style: solid;"><a
					href="javascript:void(0)" id="coachStaff-grid-add"
					class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
					<a href="javascript:void(0)" id="coachStaff-grid-delete"
					class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
					<a href="javascript:void(0)" id="coachStaff-grid-edit"
					class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
					<a href="javascript:void(0)" id="coachStaff-grid-search"
					class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
					<a href="javascript:void(0)" id="coachStaff-grid-Excel"
					class="easyui-linkbutton" data-options="iconCls:'icon-search'">导出Excel</a>
				</td>
			</tr>
		</table>
	</div>

	<table id="coachStaff-grid"></table>

	<div id="coachStaff-menu" class="easyui-menu" style="width: 160px;">
		<div id="coachStaff-menu-view" data-options="iconCls:'icon-search'">查看</div>
		<div id="coachStaff-menu-delete" data-options="iconCls:'icon-remove'">删除</div>
		<div data-options="iconCls:'icon-edit'">
			<span>编辑</span>
			<div>
				<div id="coachStaff-menu-info" data-options="iconCls:'icon-info'">企业信息</div>
				<div id="coachStaff-menu-state" data-options="iconCls:'icon-state'">有效状态</div>
				<div id="coachStaff-menu-area" data-options="iconCls:'icon-area'">实际经营区域</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
    function func(){
        var vs = $('select  option:selected').val();
        alert(vs);
    }
    $(function(){
        $("#coachStaff-grid").datagrid({
            title:"教练员管理",
            toolbar:"#coachStaff-grid-toolbar",
            border:false,
            fit:true,
            width:$(window).width()-252,
            columns:[[
                {field:"ckb",checkbox:true},
                {field:"id",title:"id",width:200,halign:"center",align:"center",resizable:true,sortable:true},
                {field:"coachName",title:"教练名",width:200,halign:"center",align:"center",resizable:true},
                {field:"coachIdCard",title:"教练身份证号",width:80,align:"center",resizable:false},
                {field:"cIC",title:"学牌编码",width:80,align:"center",resizable:false},
//                 {field:"cn",title:"学牌编码",width:80,align:"center",resizable:false},
                {field:"createTime",title:"创建时间",width:80,align:"center",resizable:false,formatter:function(value,row,index){
                	if (row.createTime){
    					//格式化时间,formatDateTime在 DataUtil.js文件中
    					return formatDateTime(row.createTime);
    				                           } else {
    					return row.createTime;
    				}	
                }
                	},
                {field:"createName",title:"创建人",width:80,align:"center",resizable:false},
                {field:"updateTime",title:"修改时间",width:80,align:"center",resizable:false,formatter:function(value,row,index){
                	if (row.updateTime){
    					//格式化时间,formatDateTime在 DataUtil.js文件中
    					return formatDateTime(row.createTime);
    				} else {
    					return row.createTime;
    				}	
                }
                	},
                {field:"updateName",title:"修改人",width:80,align:"center",resizable:false},
               
            ]],
            //striped:true,
            fitColumns:true,
            //autoRowHeight:true,
            rownumbers:false,
            singleSelect:false,
            ctrlSelect:true,
            pagination:true,
            pageSize:10,
            pageList:[5,10,15,20,25,30],
            sortName:"corpId",
            sortOrder:"desc",
            url:"CoachStaffServlet?method=query",
            method:"get",
            loadMsg:"加载数据中，请稍后",
            //双击事件
            onDblClickRow:function(rowIndex, rowData){
                var selTr = $("#coachStaff-grid").datagrid("getSelections");
                openDialog({
                    type:"view",
                    title:"教练员管理",
                    width:800,
                    height:400,
                    maximizable:true,
                    queryParams: { id: selTr[0].id},//设置了一个属性queryParams
                    href:"html/coachStaff/coachStaffDetails.html"
                });
            },
            onRowContextMenu:function(e, rowIndex, rowData){
                e.preventDefault();

                $(this).datagrid("unselectAll");

                $(this).datagrid("selectRow", rowIndex);

                $("#coachStaff-menu").menu("show",{
                    left:event.pageX,
                    top:event.pageY
                });
            }
        }).datagrid("columnMoving")
                .datagrid("columnHiding");


        //相关功能按钮事件
        $("#coachStaff-grid-search").click(function(){
            $("#coachStaff-grid").datagrid("load",{
            	coachName:$("#coachName").val(),
            	coachIdCard:$("#coachIdCard").val(),
            	cIC:$("#cIC").val(),
            	cn:$("#cn").val()
            });
        });

        $("#coachStaff-grid-add").click(function(){
            openDialog({
                title:"用户管理",
                width:800,
                height:260,
                maximizable:false,
                href:"html/coachStaff/coachStaffAdd.html"
            });
        });
       
		$("#coachStaff-grid-Excel").click(function(){
			location.href="ExcelExportServlet";
        });

        $("#coachStaff-grid-delete").click(function(){
            var selTr = $("#coachStaff-grid").datagrid("getSelections");

            if(selTr.length == 0){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:"请至少选择1条记录"
                });
            }else{
                var strIds = "";
                //拼接字符串，这里也可以使用数组，作用一样
                for (var i = 0; i < selTr.length; i++) {
                    strIds += selTr[i].id + ",";
                }
                $.ajax({
                    url :'CoachStaffServlet?method=delete&ids='+strIds,
                   
                    dataType : 'json',
                    type : 'delete',
                    success : function(data) {
                     	if(data.resultCode=="1"){
	                        Messager.show({
	                            title:"&nbsp;",
	                            content:"删除成功"
	                        });
	                        $("#coachStaff-grid-search").click();
                    	}else{
                    		 Messager.show({
 	                            title:"&nbsp;",
 	                            content:data.resultMessage
 	                        });
                    	}
                    },
                    //400 500,505异常进入,不是json类型的数据
                    error : function(data) {
                        Messager.show({
                            title:"&nbsp;",
                            content:"删除失败"
                        });
                    }
                });
            }
        });

        $("#coachStaff-grid-edit").click(function(){
            var selTr = $("#coachStaff-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"用户信息编辑",
                    width:800,
                    height:360,
                    maximizable:false,
                    queryParams: { id: selTr[0].id},//设置了一个属性queryParams
                    href:"html/coachStaff/coachStaffAddEdit.html"
                });
            }
        });

        $("#coachStaff-grid-area").click(function(){
            var selTr = $("#coachStaff-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"泥头车企业实际经营区域编辑",
                    width:500,
                    height:280,
                    maximizable:false,
                    href:"BaseInfo/Corp/CorpAreaEdit.html"
                });
            }
        });

        $("#coachStaff-grid-state").click(function(){
            var selTr = $("#coachStaff-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"泥头车企业有效状态编辑",
                    width:500,
                    height:320,
                    maximizable:false,
                    href:"BaseInfo/Corp/CorpStateEdit.html"
                });
            }
        });


        //菜单相关按钮事件
        $("#coachStaff-menu-view").click(function(){
            $("#coachStaff-grid").datagrid("options").onDblClickRow();
        });

        $("#coachStaff-menu-delete").click(function(){
            $("#coachStaff-grid-delete").click();
        });

        $("#coachStaff-menu-info").click(function(){
            $("#coachStaff-grid-edit").click();
        });

        $("#coachStaff-menu-area").click(function(){
            $("#coachStaff-grid-area").click();
        });

        $("#coachStaff-menu-state").click(function(){
            $("#coachStaff-grid-state").click();
        });
    });
</script>
</body>
</html>